package com.huanwei.questionfragment;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.huanwei.cc.R;
import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.bean.FanKui;
import com.huanwei.cc.bean.MyEvent;
import com.huanwei.cc.db.Z_FanKui_Dao;
import com.huanwei.questionfragment.adapter.fk_Adapter;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

/**
 * Created by zhuwenhai on 2017/12/1.
 * 用户列表
 */

public class FK_Activity extends AppCompatActivity {


    Z_FanKui_Dao z_msgDao;
    ListView lvList;
    fk_Adapter bank_card_adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fk_share);
        ButterKnife.bind(this);
        initViewsAndEvents();
    }


    public void initViewsAndEvents() {
        EventBus.getDefault().register(this);

        lvList = (ListView) findViewById(R.id.lv_list);//设置;
        lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            }
        });
        z_msgDao = new Z_FanKui_Dao(MyApplication.getInstance());
        List<FanKui> query = z_msgDao.query();
        bank_card_adapter = new fk_Adapter();
        bank_card_adapter.setactivity(FK_Activity.this);
        lvList.setAdapter(bank_card_adapter);
        if (query != null && query.size() > 0) {
            bank_card_adapter.addItem(query);
        } else {
            Toast.makeText(this, "暂无反馈", Toast.LENGTH_SHORT).show();
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void onEventMainThread(MyEvent event) {

        if (!TextUtils.isEmpty(event.getType())) {
            if (event.getType().equals("shua")) {
                List<FanKui> query = z_msgDao.query();
                lvList.setAdapter(bank_card_adapter);
                bank_card_adapter.clear();
                bank_card_adapter.addItem(query);
            }
        }
    }


    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }
}